package com.kly.user.task.service;

import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.kly.user.db.dao.TRuleHistoryLogDao;
import com.kly.user.db.entity.UserTaskJobEntity;
import com.kly.user.task.ExecuteHandler;
import com.kly.user.task.ExecuteResult;
import com.kly.user.task.enums.TaskStatusEnum;
import com.kly.user.task.enums.TaskTypeEnum;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 日志清理
 */
@Service("removeLogImpl")
public class RemoveLogImpl implements ExecuteHandler {
    private static Log logger = LogFactory.getLog("taskFileLog");
    @Resource
    TRuleHistoryLogDao ruleHistoryLogDao;

    @Override
    public TaskTypeEnum getType() {
        return TaskTypeEnum.REMOVE_LOG;    }

    @Override
    public <T> ExecuteResult doExecute(T t) throws Exception {
        UserTaskJobEntity entity = (UserTaskJobEntity) t;
        ruleHistoryLogDao.removeLogs(-7);
        return ExecuteResult.builder().jobId(entity.getId()).resultMsg("success")
                .resultCode(TaskStatusEnum.SUCCESS.getCode()).taskType(TaskTypeEnum.REMOVE_LOG.getCode()).build();
    }

}
